//
//  PPCheckManager.m
//  Pods-PPCheckTool_Example
//
//  Created by BenJim on 2019/4/5.
//

#import "PPCheckManager.h"

@implementation PPCheckManager

- (NSString *)getAppID{
    
    // ---- 子类实现
    return @"";
}

- (NSString *)getAppKey{
    
    // --- 子类实现
    return @"";
}


- (NSString *)getRouterAddress{
    
    // --- 子类实现

    return @"";

}

- (void)startCheckSucceedCallBack:(void (^)(id _Nonnull))succeedCallBack FailCallBack:(void (^)(NSError * _Nonnull))failCallBack{

    NSURLSessionConfiguration *configure=[NSURLSessionConfiguration defaultSessionConfiguration];
    
    NSURLSession *session=[NSURLSession sessionWithConfiguration:configure];
    
    NSString * requestUrl = [self getRouterAddress];
    
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:requestUrl]];
    
    request.HTTPMethod=@"GET";
    
    [request setValue:[self getAppID] forHTTPHeaderField:@"X-LC-Id"];
    
    [request setValue:[self getAppKey] forHTTPHeaderField:@"X-LC-Key"];
    
    NSURLSessionDataTask *task=[session dataTaskWithRequest:request
                                          completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                                              if (data != nil) {
                                                  id result = [NSJSONSerialization JSONObjectWithData:data                                                                                               options:NSJSONReadingAllowFragments
                                                                                                error:NULL];
                                                  if (data) {
                                                      succeedCallBack(result);
                                                  }else{
                                                      failCallBack(error);
                                                  }
                                              }
                                          }];
    [task resume];
}

@end
